package com.hhxy.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 测试Response对象的getOutputStream方法和getWriter方法
 * @author ghp
 * @date 2022/9/13
 */
@WebServlet("/printServlet")
public class PrintServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String data = "it-cast";
        /*
        1、测试getOutputStream方法
        ServletOutputStream sos = response.getOutputStream();
        sos.write(data.getBytes());
        */

        //2、测试getWriter方法
        PrintWriter pw = response.getWriter();
        pw.write(data);
    }
}